import { Component ,ViewChild} from '@angular/core';
import { CTAFComponent,ComponentBase,BackendService } from '@ctaf/framework';
import { AmChartsComponent, GridOptions } from '@ctaf/components';
import './medalList.less';
import * as _ from 'underscore';
import { max } from 'rxjs/operator/max';
@CTAFComponent({
    selector: 'qdm-medalList',
    templateUrl: 'medalList.component.html'
})
export class MedalListComponent extends ComponentBase {
    gridOptions: GridOptions;

    public startDate = new Date(2018,1,1);
    public endDate = new Date(2018,12,31);
    public countryOptions = [{orgKey:'中国',orgName:'中国'},{orgKey:'美国',orgName:'美国'},{orgKey:'英国',orgName:'英国'},{orgKey:'法国',orgName:'法国'}];   
    public sexOptions = [{orgKey:'男性',orgName:'男性'},{orgKey:'女性',orgName:'女性'}];   
    private countryOrg: string = '中国';
    private sexOrg: string = '男性';    
    private ifCombinaShow: boolean = false;


    rowData = [];//表格内容数据
    private data = {
        'pageSize': 16,
        'total': 40,
        'currentPage':1
    }
    constructor(  private backendService: BackendService){
        super();
    }
    ngOnInit() {
        //表格标题
        let columnDefs = [
            { headerName: 'Athlete', field: 'athlete', width: 150 },
            { headerName: 'Age', field: 'age', width: 90 },
            { headerName: 'Country', field: 'country', width: 120 },
            { headerName: 'Year', field: 'year', width: 90 },
            { headerName: 'Date', field: 'date', width: 110 },
            { headerName: 'Sport', field: 'sport', width: 110 },
            { headerName: 'Gold', field: 'gold', width: 100 },
            { headerName: 'Silver', field: 'silver', width: 100 },
            { headerName: 'Bronze', field: 'bronze', width: 100 },
            { headerName: 'Total', field: 'total', width: 100 }
        ];

        //设置表格属性
        this.gridOptions = {
            columnDefs: columnDefs,
            enableRangeSelection: true,
            rowData: this.rowData,
            suppressMenuFilterPanel: true,
            suppressMenuMainPanel: true,
            suppressMenuColumnPanel: true,
            headerHeight: 25,
            rowHeight: 28
        };
        this.getData(1);//初始表格显示第一页
    }
    //通过data.json文件模拟get请求
    getData(page){
        var url = "../../src/tempdata/data"+page+".json";
        this.backendService.get(url).
            then(data=>{
                this.gridOptions.rowData = data;  
                this.gridOptions.api.setRowData(data);
        })
        .catch();
    }
    change(event){
        this.getData(event.currentPage);
    }
    //统一查询
    search(){
        var combinaShow = this.ifCombinaShow?"是":"不";
        alert("您选择的是:"+this.countryOrg+this.sexOrg+"运动员,于"+this.startDate+"至"+this.endDate+"期间获得奖牌,"+combinaShow+"组合展示");
        //查询操作...
    }
    alertShow(){
        alert(123)
    }
    
}
export class ShowDialogComponent extends ComponentBase {

    @ViewChild('dialog1') dialog1;
    private display: boolean = false;

    ngOnInit() {
    this.dialog1.onConfirm.subscribe((e) => {
        this.display = false;
        alert('confirm');
    });

    this.dialog1.onCancel.subscribe((e) => {
        this.display = false;
        alert('cancel');
    });
}
}




